home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue44 / comcorn / ByteArray / ServObj.pas < prev   
Encoding:
Pascal/Delphi Source File  |  1999-03-01  |  1.1 KB  |  57 lines

  1. unit ServObj;
  2.  
  3. interface
  4.  
  5. uses
  6.   ComObj, ActiveX, Server_TLB;
  7.  
  8. type
  9.   TBinaryData = class(TAutoObject, IBinaryData)
  10.   protected
  11.     function Get_Data: OleVariant; safecall;
  12.     procedure Set_Data(Value: OleVariant); safecall;
  13.   end;
  14.  
  15. implementation
  16.  
  17. uses ComServ, ServMain;
  18.  
  19. function TBinaryData.Get_Data: OleVariant;
  20. var
  21.   P: Pointer;
  22.   L: Integer;
  23. begin
  24.   // Move data from memo into array
  25.   L := Length(MainForm.Memo.Text);
  26.   Result := VarArrayCreate([0, L - 1], varByte);
  27.   P := VarArrayLock(Result);
  28.   try
  29.     Move(MainForm.Memo.Text[1], P^, L);
  30.   finally
  31.     VarArrayUnlock(Result);
  32.   end;
  33. end;
  34.  
  35. procedure TBinaryData.Set_Data(Value: OleVariant);
  36. var
  37.   P: Pointer;
  38.   L: Integer;
  39.   S: string;
  40. begin
  41.   // Move data from array into memo
  42.   L := VarArrayHighBound(Value, 1) - VarArrayLowBound(Value, 1) + 1;
  43.   SetLength(S, L);
  44.   P := VarArrayLock(Value);
  45.   try
  46.     Move(P^, S[1], L);
  47.   finally
  48.     VarArrayUnlock(Value);
  49.   end;
  50.   MainForm.Memo.Text := S;
  51. end;
  52.  
  53. initialization
  54.   TAutoObjectFactory.Create(ComServer, TBinaryData, Class_BinaryData,
  55.     ciSingleInstance, tmApartment);
  56. end.
  57.